﻿@model TestOnlineProject.Models.Entities.Participant
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
        <script> alert("@ViewBag.Msg")</script>
    }
}
<script>
    $(document).ready(function () {
        $("#deactivate").click(function () {
            var con = confirm("Are you sure you want to deactivate this participant?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Participant/Deactivate")?userIds=" + "@Model.UserId" + "-" + "&subjectId=" + @Model.SubjectId,
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Participant/Details")?userId=@Model.UserId&subjectId=@Model.SubjectId";
                        }
                    }
                })
            }
        }); $("#activate").click(function () {
            var con = confirm("Are you sure you want to activate this participant?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Participant/Activate")?userIds=" + "@Model.UserId" + "-" + "&subjectId=" + @Model.SubjectId,
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                             window.location = "@Url.Content("~/Participant/Details")?userId=@Model.UserId&subjectId=@Model.SubjectId";
                        }
                    }
                })
            }
        });

        $("#delete").click(function () {
            var con = confirm("Are you sure you want to delete this participant?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Participant/Delete")?userIds=" + "@Model.UserId" + "-" + "&subjectId=" + @Model.SubjectId,
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                             window.location = "@Url.Content("~/Participant/Index")?subjectId=@Model.SubjectId";
                        }
                    }
                })
            }
        });
    })
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject")
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    /
    @Html.ActionLink("Participants", "Index", "Participant", new { subjectId = (ViewBag.Subject as Subject).SubjectId }, null)
    / @Model.User.FullName</div>
<br />
<div class="main_nav">
    <span>
        <a href="@Url.Content("~/Participant/Index")?subjectId=@Model.SubjectId">
            <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
        </a>
    </span>
</div>
<br />
@{
    if (!Model.IsActivated)
    {
    <div class="alert alert-error">
        <span>Deactivated.</span>
    </div>
    }
}
<table class="table table-bordered">
    <tr>
        <td style="width: 150px; text-align: right">
            User
        </td>
        <td>
            @Html.ActionLink(@Model.User.FullName, "Index", "Account", new { userId = @Model.UserId }, new { target = "_blank" })
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            Joined Time
        </td>
        <td>
            @Model.JoinedTime
        </td>
    </tr>
    @{
        if (HttpContext.Current.User.IsInRole("1"))
        {
            <tr>
                <td style="text-align: right">
                </td>
                <td>
                    @{
                        if (Model.IsActivated)
                        {
                            <a href="#" id="deactivate">Deactivate</a>
                        }
                        else
                        {
                            <a href="#" id="activate">Activate</a>
                        }
                        <span>|</span>
                    }
                    <a href="#" id="delete">Delete</a>
                </td>
            </tr>
        }
    }
</table>